#!/bin/bash

echo "🛑 正在关闭服务..."

# 读取并终止 chatbot 进程
if [ -f "chatbot.pid" ]; then
    CHATBOT_PID=$(cat chatbot.pid)
    kill $CHATBOT_PID && echo "✅ 已关闭 Chatbot (PID=$CHATBOT_PID)" || echo "⚠️ 未能关闭 Chatbot"
    rm chatbot.pid
else
    echo "⚠️ 找不到 chatbot.pid，尝试手动关闭 Chatbot"
fi

# 读取并终止 Mineru 进程
if [ -f "MinerU/mineru.pid" ]; then
    MINERU_PID=$(cat MinerU/mineru.pid)
    kill $MINERU_PID && echo "✅ 已关闭 Mineru (PID=$MINERU_PID)" || echo "⚠️ 未能关闭 Mineru"
    rm MinerU/mineru.pid
else
    echo "⚠️ 找不到 mineru.pid，尝试手动关闭 Mineru"
fi

echo "🧹 服务关闭完毕。"
